/**
 * Created by lucas on 2017/3/19.
 */
"use strict";

import React, {Component, PropTypes} from 'react';

export default class Suggest extends Component {

    static propTypes = {
        options: PropTypes.arrayOf(PropTypes.string),
    };

    state = {
        value: this.props.defaultValue,
    };

    getValue() {
        return this.state.value;
    }

    render() {
        const randomid = Math.random().toString(16).substring(2);
        return (
            <div>
                <input list={randomid} defaultValue={this.props.defaultValue} id={this.props.id} onChange={event => this.setState({value: event.target.value})} />
                <datalist id={randomid}>
                    {
                        this.props.options.map((item, index) => <option value={item} key={index} />)
                    }
                </datalist>
            </div>
        );
    }
}